package com.zf.nospring.rabbitmq.delay.ttl;

import com.rabbitmq.client.*;
import com.zf.nospring.rabbitmq.utils.RabbitUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 消费 队列中的消息
 */
public class DelayMessageConsumerByTtl {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitUtils.getDefaultConnection();
        Channel channel = connection.createChannel();

        // 消费逻辑
        DefaultConsumer consumer = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.printf("envelope: %s, msg: %s\n", envelope, new String(body));
            }
        };
        // 消费死信队列，实现延迟消费
        channel.basicConsume("test_delay_dead_queue", true, consumer);
    }
}
